📉 Schema Migration Analysis
TL;DR
Metis can scan your pull requests for changes in your database schema, analyze those changes and show you insights about them.
How it works
The SQL commands used for changing the schema of the databases are usually stored in a folder.
ORMs manages the SQL commands in a folder, usually with a subfolder for each version.
The GitHub Action review all the migration SQL commands and sends them to Metis, which analyze them and warn about the impact on the database.
Prerequisites
A Metis account with a valid API key. 🥽 Create a project & generate API key
Installation
On code with ORMs that generates SQL files:
Link to the action in GitHub marketplace
Add the following code to your GitHub Actions workflow file:
- name: Analyze migrations
uses: metis-data/sql-migrations-validator@v1
with:
from: ${{ github.event.pull_request.base.sha }}
to: ${{ github.event.pull_request.head.sha }}
github_token: ${{ github.token }}
metis_api_key: <Your Api Key>
Parameters
from
- PR base sha to be comparedto
- PR base sha to be compared withfrom
PRgithub_token
- Auto generated workflow GitHub tokenmetis_api_key
- Metis Api Key 🥽 Create a project & generate API key
Github workflow example
on:
pull_request:
types: [opened, reopened, edited, synchronize, ready_for_review]
jobs:
migrations:
name: Analyze new migrations
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Compare migrations
uses: metis-data/sql-migrations-validator@v1
with:
from: ${{ github.event.pull_request.base.sha }}
to: ${{ github.event.pull_request.head.sha }}
github_token: ${{ github.token }}
metis_api_key: <Your Api Key>
On JS code with Sequelize ORM:
Link to the action in GitHub marketplace
Please use standard Sequelize migrations files that generated by Sequelize CLI and exports up/down functions from module.
Add the following code to your GitHub Actions workflow file:
- name: Analyze migrations
uses: metis-data/sequelize-migrations-validator@v1
with:
from: ${{ github.event.pull_request.base.sha }}
to: ${{ github.event.pull_request.head.sha }}
github_token: ${{ github.token }}
metis_api_key: <Your Api Key>
migrations_dir: <path/to/migrations/directory>
Parameters
from
- Base sha to be comparedto
- Branch sha to be compared withgithub_token
- Auto generated workflow GitHub tokenmetis_api_key
- Metis Api Key generated at Metismigrations_dir
- Path in your project to Sequelize migrations directory
Github workflow example
on:
pull_request:
types: [opened, reopened, edited, synchronize, ready_for_review]
jobs:
migrations:
name: Analyze new migrations
runs-on: ubuntu-latest
services:
postgres:
image: postgres
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Compare migrations
uses: metis-data/sql-migrations-validator@v1
with:
from: ${{ github.event.pull_request.base.sha }}
to: ${{ github.event.pull_request.head.sha }}
github_token: ${{ github.token }}
metis_api_key: <Your Api Key>
migrations_dir: migrations